{% load static %}
<!-- 导航栏 -->
<nav class="navbar navbar-expand-lg navbar-light bg-white shadow-sm sticky-top">
    <div class="container">
        <a class="navbar-brand" href="/meet/index/">
            <i class="fas fa-map-marker-alt me-2"></i>城会玩
        </a>
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarNav">
            <ul class="navbar-nav me-auto">
                <li class="nav-item">
                    <a class="nav-link {% if request.path == '/meet/index/' %}active{% endif %}" href="/meet/index/">首页</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link {% if request.path == '/meet/active/' %}active{% endif %}" href="/meet/active/">发现活动</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="/meet/create_activity/">创建活动</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link {% if request.path == '/meet/social/' %}active{% endif %}"  href="/meet/social/">社区</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="/user/talking/">聊天</a>
                </li>
            </ul>

            <!-- 修改这部分：登录注册逻辑 -->
            <div class="d-flex">
                {% if request.user.is_authenticated %}
                    <div class="dropdown">
                        <button class="btn btn-outline-primary dropdown-toggle me-2" type="button" data-bs-toggle="dropdown" aria-expanded="false">
                             {% if user.avatar %}
                                <img src="{{ user.avatar.url }}" alt="{{ user.username }}" class="rounded-circle me-2" width="32" height="32" onerror="this.src='/static/images/default-avatar.png'">
                            {% else %}
                                <img src="/static/images/default-avatar.png" alt="{{ user.username }}" class="rounded-circle me-2" width="32" height="32">
                            {% endif %}
                            {{ request.user.username }}
                        </button>
                        <ul class="dropdown-menu">
                            <li><a class="dropdown-item" href="/user/person_center/">
                                <i class="fas fa-user me-2" style="color: #FF6B35;"></i>个人中心
                            </a></li>
                            <li><a class="dropdown-item" href="/meet/history/">
                                <i class="fas fa-edit me-2" style="color: #FF6B35;"></i>浏览历史
                            </a></li>
                            <li><a class="dropdown-item" href="/user/points/mall/">
                                <i class="fas fa-coins me-2" style="color: #FF6B35;"></i>积分商城
                            </a></li>
                            {% if request.user.is_staff or request.user.is_superuser %}
                                <li><a class="dropdown-item" href="/user/admin_index/">
                                    <i class="fas fa-cog me-2" style="color: #FF6B35;"></i>管理后台
                                </a></li>
                            {% endif %}
                            <li><hr class="dropdown-divider"></li>
                            <li><a class="dropdown-item" href="/user/logout/">
                                <i class="fas fa-sign-out-alt me-2" style="color: #FF6B35;"></i>退出登录
                            </a></li>
                        </ul>
                    </div>
                {% else %}
                    <a href="/user/login/" class="btn btn-outline-primary me-2">
                        <i class="fas fa-sign-in-alt me-1"></i>登录
                    </a>
                    <a href="/user/register/" class="btn btn-primary">
                        <i class="fas fa-user-plus me-1"></i>注册
                    </a>
                {% endif %}
            </div>
        </div>
    </div>
</nav>